#include <iostream>
#include <vector>
#include <stack>
using namespace std;

void dfs(vector<vector<int>> &gh, vector<int> &vis, int u, stack<int> &link)
{
	vis[u] = 1;
	for (auto v : gh[u]) {
		if (!vis[v]) {
			dfs(gh, vis, v, link);
		}
	}
	link.push(u);
}

int main()
{
	int n, m;
	cin >> n >> m;
	vector<vector<int>> gh(n + 1);
	vector<long> num(n + 1, 0);
        vector<int> vis(n + 1, 0);

	for (int i = 0, u, v; i < m; i++) {
		cin >> u >> v;
		gh[v].push_back(u);
	}

	stack<int> link;
	long ans = 0;
	for (int i = 1; i <= n; i++) {
		if (!vis[i]) {
			dfs(gh, vis, i, link);
		}
	}

        fill(vis.begin(), vis.end(), 0);
	while (!link.empty()) {
		int u = link.top();
		link.pop();

                if(vis[u] == 0){
                        vis[u] = 1;
                        num[u] = 1;
                }

                if(gh[u].size() == 0){
                        ans = (ans + num[u])%80112002;
                }

		for (auto v : gh[u]) {
                        vis[v] = 1;
			num[v] = (num[v] + num[u])%80112002;
		}
	}
	cout << ans << endl;
	return 0;
}